<template>
<!-- 视频号优质视频号推荐 -->
              <div class="alll-video-box" @click.stop="gotoTvInfo(videoData.video_id)" >
                <div class="video-img" >
                  <img :src="videoData.video_cover.video_cover_url" :style="coverSize" alt="" />
                  <div class="duration">{{duration}}</div>
                </div>
                <div class="video-infotitle">
                  {{videoData.video_title}}<!--超过25个字后面的以...代替--->
                </div>
                <div class="publish-info">
                  <span class="views">{{videoData.video_play_num}}次观看 </span> •
                  <span class="publish-days">{{videoData.video_time}}</span>
                </div>
              </div>
</template>

<script>
import http from '@/util/http'
import { mapState } from 'vuex'
export default {
  props: {
    videoData: {
      type: Object,
      default: null
    }
  },

  computed: {
    ...mapState(['user']),
    // 显示视频封面的中心部分
    coverSize () {
      const a = {}
      if (this.videoData.video_cover.width >= this.videoData.video_cover.height) {
        a.width = this.videoData.video_cover.width / this.videoData.video_cover.height * 100 + '%'
        a.left = -(this.videoData.video_cover.width / this.videoData.video_cover.height - 1) / 2 * 100 + '%'
        a.height = '100%'
      } else {
        a.height = this.videoData.video_cover.height / this.videoData.video_cover.width * 100 + '%'
        a.top = -(this.videoData.video_cover.height / this.videoData.video_cover.width - 1) / 2 * 100 + '%'
        a.width = '100%'
      }
      return a
    },
    // 显示视频的时长
    duration () {
      let time = ''
      if (this.videoData.video_duration < 60) {
        let miao = this.videoData.video_duration
        if (this.videoData.video_duration < 10) {
          miao = '0' + this.videoData.video_duration
        }

        time = '0:' + miao
      } else if (this.videoData.video_duration > 60 && this.videoData.video_duration < 3600) {
        let fen = null
        let miao = null
        fen = Math.trunc(this.videoData.video_duration / 60)
        miao = Math.trunc(this.videoData.video_duration % 60)
        if (miao < 10) {
          miao = '0' + miao
        }
        if (fen < 10) {
          fen = '0' + fen
        }
        time = fen + ':' + miao
      } else if (this.videoData.video_duration > 3600) {
        let shi = null
        let fen = null
        let miao = null
        shi = Math.trunc(this.videoData.video_duration / 3600)
        fen = Math.trunc((this.videoData.video_duration % 36000) / 60)
        miao = Math.trunc(this.videoData.video_duration % 60)
        if (miao < 10) {
          miao = '0' + miao
        }
        if (fen < 10) {
          fen = '0' + fen
        }
        time = shi + ':' + fen + ':' + miao
      }

      return time
    }
  },
  methods: {
    // 跳转到视频详情页面
    gotoTvInfo (vid) {
      this.$router.push({ path: '/videodetail', query: { videoId: vid } })
      // 记录播放历史
      // 传递观看者的id和视频的id
      http.addTvhistory(this.user.uid, vid).then(res => {
        console.log(res.data)
      })
    }
  }
}
</script>

<style lang='scss' scoped>
    .alll-video-box {
              width: 22%;
              display: flex;
              flex-direction: column;
              margin-top: 10px;
              padding-bottom: 10px;
              padding-left: 10px;
            cursor: pointer;
              .video-img {
                width: 100%;
                height: 120px;
                overflow: hidden;
                border-radius: 5px;
                position: relative;
                cursor: pointer;

                img {
                  display: block;
                  width: 100%;
                  height: 100%;
                  object-fit: cover;
                  border-radius: 5px 5px 0 0;
                  transition: all 0.3s;
                  position: absolute;
                  &:hover {
                    filter: brightness(70%);
                    transform: scale(1.1);
                    opacity: 1;
                  }
                }
                .duration {
                  color: #eee;
                  font-size: 12px;
                  padding: 0 5px;
                  background: rgba($color: #000, $alpha: 0.8);
                  position: absolute;
                  bottom: 5%;
                  right: 5%;
                }
              }
              .video-infotitle {
                font-size: 14px;
                font-family: "微软雅黑";
                font-weight: 700;
                color: #333;
                 padding: .1rem .05rem  .05rem;
                height: 40px;
                line-height: 18px;
                display: -webkit-box;
                -webkit-line-clamp: 2; //显示两行he
                -webkit-box-orient: vertical;
                overflow: hidden;
                text-overflow: ellipsis; //多的用省略号显示
                word-wrap: break-word; //在合适的点换行
                word-break: break-all; //允许长单词换行到下一行
                cursor: pointer;
                &:hover {
                  color: #f90;
                }
              }
              .publish-info {
                line-height: 16px;
                font-size: 12px;
                color: #939393;
                padding-top: 6px;
              }
            }

    @media screen and (min-width:512px) and (max-width:768px) {
          .alll-video-box {
              width: 22%;
              display: flex;
              flex-direction: column;
              margin-top: 10px;
              padding-bottom: 10px;
              padding-left: 10px;
            cursor: pointer;
              .video-img {
                width: 100%;
                height: 120px;
                overflow: hidden;
                border-radius: 5px;
                position: relative;
                cursor: pointer;

                img {
                  display: block;
                  width: 100%;
                  height: 100%;
                  object-fit: cover;
                  border-radius: 5px 5px 0 0;
                  transition: all 0.3s;
                  position: absolute;
                  &:hover {
                    filter: brightness(70%);
                    transform: scale(1.1);
                    opacity: 1;
                  }
                }
                .duration {
                  color: #eee;
                  font-size: 12px;
                  padding: 0 5px;
                  background: rgba($color: #000, $alpha: 0.8);
                  position: absolute;
                  bottom: 5%;
                  right: 5%;
                }
              }
              .video-infotitle {
                font-size: 14px;
                font-weight: 700;
                color: #333;
                 padding: 10px 5px  5px;
                height: 40px;
                line-height: 20px;
                display: -webkit-box;
                -webkit-line-clamp: 2; //显示两行he
                -webkit-box-orient: vertical;
                overflow: hidden;
                text-overflow: ellipsis; //多的用省略号显示
                word-wrap: break-word; //在合适的点换行
                word-break: break-all; //允许长单词换行到下一行
                cursor: pointer;
                &:hover {
                  color: #f90;
                }
              }
              .publish-info {
                line-height: 16px;
                font-size: 12px;
                color: #939393;
                padding-top: 6px;
              }
            }
          }
</style>
